@extends('admin.layout.layout')
@section('content')
<style type="text/css">
  .delete{cursor:pointer;}
</style>
<div class="col-lg-12">
    <div class="panel panel-default">
        @if (count($errors) > 0)    
            <div class="alert alert-danger">
                <ul>
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif
        <div class="panel-heading">
            友链列表
        </div>
        <!-- /.panel-heading -->
        <div class="panel-body">
          <div class="dataTable_wrapper">
            <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
              <div class="row">
              <form action="{{url('/admin/friend/index')}}" method="get">
                <div class="col-sm-6">
                  <div class="dataTables_length" id="dataTables-example_length">
                    <label>显示
                      <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                        <option value="10" @if(!empty($request['num']) && $request['num'] == 10) { selected } @endif>10</option>
                        <option value="25" @if(!empty($request['num']) && $request['num'] == 25) { selected } @endif>25</option>
                        <option value="50" @if(!empty($request['num']) && $request['num'] == 50) { selected } @endif>50</option>
                        <option value="100" @if(!empty($request['num']) && $request['num'] == 100) { selected } @endif>100</option></select>条</label>
                  </div> 
                </div>
                
                <div class="col-sm-6">
                  <div id="dataTables-example_filter" class="dataTables_filter">
                    <label>友链名称:
                      <input type="search" value="@if(!empty($request['keywords'])){{$request['keywords']}}@endif" name="keywords" class="form-control input-sm" placeholder="" aria-controls="dataTables-example"></label>
                      <button  class="btn btn-primary">查询</button>
                  </div>

                </div>
                </form>
              </div>
              <div class="row">
                <div class="col-sm-12">
                  <table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info" style="table-layout:fixed;">
                    <thead>
                      <tr role="row">
                        <th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending">ID</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending">友链名称</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending">友链地址</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="Engine version: activate to sort column ascending">友链logo</th>
                        <th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending">操作</th></tr>
                    </thead>
                    <tbody>
                    @foreach($friend as $k=>$v)
                      <tr class="gradeA odd" role="row">
                        <td class="sorting_1 sid">{{ $v->id }}</td>
                        <td>{{ $v->friend_name }}</td>
                        <td class="center">{{ $v->friend_url }}</td>
                        <td><img src="{{$v->friend_logo}}" width="90px" alt=""></td>
                        <td>
                        <a class="fa fa-trash-o delete">删除</a>
                        |
                        <a class="fa fa-wrench" href="{{url('/admin/friend/edit',['id'=>$v->id])}}">修改</a>
                        </td></tr>
                    @endforeach
                    </tbody>
                  </table>
                  <center>{!! $friend->appends($request)->render() !!}</center>
                </div>
              </div>
              </div>
            </div>
          </div>
  <!-- /.table-responsive -->
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->
</div>

@endsection
@section('myjs')
<script type="text/javascript">
$.ajaxSetup({
  headers: {
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  }
});
  $('.delete').click(function(){
    var dd = $(this);
    if(confirm("您确定要删除,删除后数据不可恢复哦?")){
      var id=dd.parents('tr').find('.sid').html();
      // alert(id);
      // 发送ajax
      $.post('/admin/friend/delete',{id:id},function(data){
        if(data == 2){
          dd.parents('tr').remove();
          message('success','友链删除成功');
        }else{
          message('error','友链删除失败');
        }
      })
    }
    return false; 
  })
  // 封装函数显示信息
  function message(er,m){
    if(er == 'success'){
      $("#messagesuccess").find("span").text(m);
      $("#messagesuccess").show();

    }else{
      $("#messagedanger").find("span").text(m);
      $("#messagedanger").show();
    }
  }
</script>
@endsection